package com.dynamixsoftware.printershare.gmail;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Vector;

public class ProtoBuf
{
  public static final Boolean FALSE = new Boolean(false);
  private static final String MSG_EOF = "Unexp.EOF";
  private static final String MSG_MISMATCH = "Type mismatch";
  private static final String MSG_UNSUPPORTED = "Unsupp.Type";
  private static Long[] SMALL_NUMBERS;
  public static final Boolean TRUE = new Boolean(true);
  private static final int VARINT_MAX_BYTES = 10;
  static final int WIRETYPE_END_GROUP = 4;
  static final int WIRETYPE_FIXED32 = 5;
  static final int WIRETYPE_FIXED64 = 1;
  static final int WIRETYPE_LENGTH_DELIMITED = 2;
  static final int WIRETYPE_START_GROUP = 3;
//  static final int WIRETYPE_VARINT;
  private ProtoBufType msgType;
  private final Vector values = new Vector();
  private final StringBuffer wireTypes = new StringBuffer();
  
  static
  {
    Long[] arrayOfLong = new Long[16];
    arrayOfLong[0] = new Long(0L);
    arrayOfLong[1] = new Long(1L);
    arrayOfLong[2] = new Long(2L);
    arrayOfLong[3] = new Long(3L);
    arrayOfLong[4] = new Long(4L);
    arrayOfLong[5] = new Long(5L);
    arrayOfLong[6] = new Long(6L);
    arrayOfLong[7] = new Long(7L);
    arrayOfLong[8] = new Long(8L);
    arrayOfLong[9] = new Long(9L);
    arrayOfLong[10] = new Long(10L);
    arrayOfLong[11] = new Long(11L);
    arrayOfLong[12] = new Long(12L);
    arrayOfLong[13] = new Long(13L);
    arrayOfLong[14] = new Long(14L);
    arrayOfLong[15] = new Long(15L);
    SMALL_NUMBERS = arrayOfLong;
  }
  
  public ProtoBuf(ProtoBufType paramProtoBufType)
  {
    this.msgType = paramProtoBufType;
  }
  
  private void assertTypeMatch(int var1, Object var2) {
      int var3 = this.getType(var1);
      if(var3 != 16 || this.msgType != null) {
         if(var2 instanceof Boolean) {
            if(var3 == 24 || var3 == 0) {
               return;
            }
         } else if(var2 instanceof Long) {
            switch(var3) {
            case 0:
            case 1:
            case 5:
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
            case 29:
            case 30:
            case 31:
            case 32:
            case 33:
            case 34:
               return;
            case 2:
            case 3:
            case 4:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            case 25:
            case 26:
            case 27:
            case 28:
            }
         } else if(var2 instanceof byte[]) {
            switch(var3) {
            case 2:
            case 25:
            case 27:
            case 28:
            case 35:
               return;
            }
         } else if(var2 instanceof ProtoBuf) {
            switch(var3) {
            case 2:
            case 3:
            case 25:
            case 26:
            case 27:
               if(this.msgType == null || this.msgType.getData(var1) == null || ((ProtoBuf)var2).msgType == null) {
                  return;
               }

               if(((ProtoBuf)var2).msgType == this.msgType.getData(var1)) {
                  return;
               }
            }
         } else if(var2 instanceof String) {
            switch(var3) {
            case 2:
            case 25:
            case 28:
            case 36:
               return;
            }
         }

         throw new IllegalArgumentException("Type mismatch type:" + this.msgType + " tag:" + var1);
      }
   }
  
//  private Object convert(Object paramObject, int paramInt)
//  {
//    boolean bool = true;
//    switch (paramInt)
//    {
//    case 17: 
//    case 18: 
//    case 20: 
//    case 29: 
//    case 30: 
//    default: 
//      throw new RuntimeException("Unsupp.Type");
//    case 24: 
//      if (!(paramObject instanceof Boolean)) {
//        break;
//      }
//    }
//    do
//    {
//      do
//      {
//        do
//        {
//          do
//          {
//            return paramObject;
//            switch ((int)((Long)paramObject).longValue())
//            {
//            default: 
//              throw new IllegalArgumentException("Type mismatch");
//            case 0: 
//              return FALSE;
//            }
//            return TRUE;
//          } while (!(paramObject instanceof Boolean));
//          Long[] arrayOfLong = SMALL_NUMBERS;
//          if (((Boolean)paramObject).booleanValue()) {}
//          for (;;)
//          {
//            return arrayOfLong[bool];
//            bool = false;
//          }
//          if ((paramObject instanceof String)) {
//            return encodeUtf8((String)paramObject);
//          }
//        } while (!(paramObject instanceof ProtoBuf));
//        ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
//        try
//        {
//          ((ProtoBuf)paramObject).outputTo(localByteArrayOutputStream);
//          byte[] arrayOfByte2 = localByteArrayOutputStream.toByteArray();
//          return arrayOfByte2;
//        }
//        catch (IOException localIOException2)
//        {
//          throw new RuntimeException(localIOException2.toString());
//        }
//      } while (!(paramObject instanceof byte[]));
//      byte[] arrayOfByte1 = (byte[])paramObject;
//      return decodeUtf8(arrayOfByte1, 0, arrayOfByte1.length, bool);
//    } while (!(paramObject instanceof byte[]));
//    try
//    {
//      ProtoBuf localProtoBuf = new ProtoBuf(null).parse((byte[])paramObject);
//      return localProtoBuf;
//    }
//    catch (IOException localIOException1)
//    {
//      throw new RuntimeException(localIOException1.toString());
//    }
//  }
  
  private Object convert(Object var1, int var2) {
      byte var3 = 1;
      switch(var2) {
      case 16:
         break;
      case 17:
      case 18:
      case 20:
      case 29:
      case 30:
      default:
         throw new RuntimeException("Unsupp.Type");
      case 19:
      case 21:
      case 22:
      case 23:
      case 31:
      case 32:
      case 33:
      case 34:
         if(var1 instanceof Boolean) {
            Long[] var10 = SMALL_NUMBERS;
            if(!((Boolean)var1).booleanValue()) {
               var3 = 0;
            }

            return var10[var3];
         }
         break;
      case 24:
         if(!(var1 instanceof Boolean)) {
            switch((int)((Long)var1).longValue()) {
            case 0:
               return FALSE;
            case 1:
               return TRUE;
            default:
               throw new IllegalArgumentException("Type mismatch");
            }
         }
         break;
      case 25:
      case 35:
         if(var1 instanceof String) {
            return encodeUtf8((String)var1);
         }

         if(var1 instanceof ProtoBuf) {
            ByteArrayOutputStream var7 = new ByteArrayOutputStream();

            try {
               ((ProtoBuf)var1).outputTo(var7);
               byte[] var9 = var7.toByteArray();
               return var9;
            } catch (IOException var12) {
               throw new RuntimeException(var12.toString());
            }
         }
         break;
      case 26:
      case 27:
         if(var1 instanceof byte[]) {
            try {
            	 ProtoBuf localProtoBuf = new ProtoBuf(null).parse((byte[])var1);
                 return localProtoBuf;
            } catch (IOException var11) {
               throw new RuntimeException(var11.toString());
            }
         }
         break;
      case 28:
      case 36:
         if(var1 instanceof byte[]) {
            byte[] var6 = (byte[])((byte[])var1);
            return decodeUtf8(var6, 0, var6.length, (boolean)(var3 != 0));
         }
      }

      return var1;
   }
  static String decodeUtf8(byte[] var0, int var1, int var2, boolean var3) {
      StringBuffer var4 = new StringBuffer(var2 - var1);

      int var6;
      for(int var5 = var1; var5 < var2; var5 = var6) {
         var6 = var5 + 1;
         int var7 = 255 & var0[var5];
         if(var7 <= 127) {
            var4.append((char)var7);
         } else if(var7 >= 245) {
            if(!var3) {
               throw new IllegalArgumentException("Invalid UTF8");
            }

            var4.append((char)var7);
         } else {
            int var8 = 224;
            int var9 = 1;
            int var10 = 128;

            int var11;
            for(var11 = 31; var7 >= var8; var11 >>= 1) {
               var8 = 128 | var8 >> 1;
               byte var20;
               if(var9 == 1) {
                  var20 = 4;
               } else {
                  var20 = 5;
               }

               var10 <<= var20;
               ++var9;
            }

            int var12 = var7 & var11;
            int var13 = 0;

            int var14;
            int var19;
            for(var14 = var6; var13 < var9; var14 = var19) {
               var12 <<= 6;
               if(var14 >= var2) {
                  if(!var3) {
                     throw new IllegalArgumentException("Invalid UTF8");
                  }

                  var19 = var14;
               } else {
                  if(!var3 && (192 & var0[var14]) != 128) {
                     throw new IllegalArgumentException("Invalid UTF8");
                  }

                  var19 = var14 + 1;
                  var12 |= 63 & var0[var14];
               }

               ++var13;
            }

            if(!var3 && var12 < var10 || var12 >= '\ud800' && var12 <= '\udfff') {
               throw new IllegalArgumentException("Invalid UTF8");
            }

            if(var12 <= '\uffff') {
               var4.append((char)var12);
               var6 = var14;
            } else {
               int var15 = var12 - 65536;
               var4.append((char)('\ud800' | var15 >> 10));
               var4.append((char)('\udc00' | var15 & 1023));
               var6 = var14;
            }
         }
      }

      return var4.toString();
   }
  static int encodeUtf8(String var0, byte[] var1, int var2) {
      int var3 = var0.length();

      for(int var4 = 0; var4 < var3; ++var4) {
         int var5 = var0.charAt(var4);
         if(var5 >= '\ud800' && var5 <= '\udfff' && var4 + 1 < var3) {
            int var6 = var0.charAt(var4 + 1);
            if((var6 & '\ufc00' ^ var5 & '\ufc00') == 1024) {
               ++var4;
               int var7;
               if((var6 & '\ufc00') == '\ud800') {
                  var7 = var6;
                  var6 = var5;
               } else {
                  var7 = var5;
               }

               var5 = 65536 + ((var7 & 1023) << 10 | var6 & 1023);
            }
         }

         if(var5 <= 127) {
            if(var1 != null) {
               var1[var2] = (byte)var5;
            }

            ++var2;
         } else if(var5 <= 2047) {
            if(var1 != null) {
               var1[var2] = (byte)(192 | var5 >> 6);
               var1[var2 + 1] = (byte)(128 | var5 & 63);
            }

            var2 += 2;
         } else if(var5 <= '\uffff') {
            if(var1 != null) {
               var1[var2] = (byte)(224 | var5 >> 12);
               var1[var2 + 1] = (byte)(128 | 63 & var5 >> 6);
               var1[var2 + 2] = (byte)(128 | var5 & 63);
            }

            var2 += 3;
         } else {
            if(var1 != null) {
               var1[var2] = (byte)(240 | var5 >> 18);
               var1[var2 + 1] = (byte)(128 | 63 & var5 >> 12);
               var1[var2 + 2] = (byte)(128 | 63 & var5 >> 6);
               var1[var2 + 3] = (byte)(128 | var5 & 63);
            }

            var2 += 4;
         }
      }

      return var2;
   }
  
  
  static byte[] encodeUtf8(String paramString)
  {
    byte[] arrayOfByte = new byte[encodeUtf8(paramString, null, 0)];
    encodeUtf8(paramString, arrayOfByte, 0);
    return arrayOfByte;
  }
  private int getDataSize(int var1, int var2) {
      int var3 = getVarIntSize((long)(var1 << 3));
      switch(this.getWireType(var1)) {
      case 0:
         long var4 = this.getLong(var1, var2);
         if(this.isZigZagEncodedType(var1)) {
            var4 = zigZagEncode(var4);
         }

         return var3 + getVarIntSize(var4);
      case 1:
         return var3 + 8;
      case 2:
      case 4:
      default:
         Object var6 = this.getObject(var1, var2, 16);
         int var7;
         if(var6 instanceof byte[]) {
            var7 = ((byte[])((byte[])var6)).length;
         } else if(var6 instanceof String) {
            var7 = encodeUtf8((String)var6, (byte[])null, 0);
         } else {
            var7 = ((ProtoBuf)var6).getDataSize();
         }

         return var7 + var3 + getVarIntSize((long)var7);
      case 3:
         return var3 + var3 + this.getProtoBuf(var1, var2).getDataSize();
      case 5:
         return var3 + 4;
      }
   }

  
  private Object getDefault(int var1) {
      switch(this.getType(var1)) {
      case 16:
      case 26:
      case 27:
         return null;
      default:
         return this.msgType.getData(var1);
      }
   }
  
  private Object getObject(int paramInt1, int paramInt2)
  {
    int i = getCount(paramInt1);
    if (i == 0) {
      return getDefault(paramInt1);
    }
    if (i > 1) {
      throw new IllegalArgumentException();
    }
    return getObject(paramInt1, 0, paramInt2);
  }
  
  private Object getObject(int paramInt1, int paramInt2, int paramInt3)
  {
    if (paramInt2 >= getCount(paramInt1)) {
      throw new ArrayIndexOutOfBoundsException();
    }
    Object localObject1 = this.values.elementAt(paramInt1);
    boolean bool = localObject1 instanceof Vector;
    Vector localVector = null;
    if (bool)
    {
      localVector = (Vector)localObject1;
      localObject1 = localVector.elementAt(paramInt2);
    }
    Object localObject2 = convert(localObject1, paramInt3);
    if ((localObject2 != localObject1) && (localObject1 != null))
    {
      if (localVector == null) {
        setObject(paramInt1, localObject2);
      }
    }
    else {
      return localObject2;
    }
    localVector.setElementAt(localObject2, paramInt2);
    return localObject2;
  }
  
  private static int getVarIntSize(long var0) {
      int var2;
      if(var0 < 0L) {
         var2 = 10;
      } else {
         for(var2 = 1; var0 >= 128L; var0 >>= 7) {
            ++var2;
         }
      }

      return var2;
   }
  
  private final int getWireType(int var1) {
      int var2 = this.getType(var1);
      switch(var2) {
      case 4:
      case 6:
      case 7:
      case 8:
      case 9:
      case 10:
      case 11:
      case 12:
      case 13:
      case 14:
      case 15:
      default:
         throw new RuntimeException("Unsupp.Type:" + this.msgType + '/' + var1 + '/' + var2);
      case 17:
      case 22:
      case 32:
         return 1;
      case 18:
      case 23:
      case 31:
         return 5;
      case 19:
      case 20:
      case 21:
      case 24:
      case 29:
      case 30:
      case 33:
      case 34:
         var2 = 0;
      case 0:
      case 1:
      case 2:
      case 3:
      case 5:
      case 16:
         return var2;
      case 25:
      case 27:
      case 28:
      case 35:
      case 36:
         return 2;
      case 26:
         return 3;
      }
   }
  private void insertObject(int var1, int var2, Object var3) {
      this.assertTypeMatch(var1, var3);
      if(this.getCount(var1) == 0) {
         this.setObject(var1, var3);
      } else {
         Object var4 = this.values.elementAt(var1);
         Vector var5;
         if(var4 instanceof Vector) {
            var5 = (Vector)var4;
         } else {
            var5 = new Vector();
            var5.addElement(var4);
            this.values.setElementAt(var5, var1);
         }

         var5.insertElementAt(var3, var2);
      }
   }
  
  private boolean isZigZagEncodedType(int paramInt)
  {
    int i = getType(paramInt);
    return (i == 33) || (i == 34);
  }
  
  static long readVarInt(InputStream paramInputStream, boolean paramBoolean)
    throws IOException
  {
    long l = 0L;
    int i = 0;
    for (int j = 0;; j++)
    {
      if (j < 10)
      {
        int k = paramInputStream.read();
        if (k == -1)
        {
          if ((j == 0) && (paramBoolean)) {
            return -1L;
          }
          throw new IOException("EOF");
        }
        l |= (k & 0x7F) << i;
        if ((k & 0x80) != 0) {}
      }
      else
      {
        return l;
      }
      i += 7;
    }
  }
  
  private void setObject(int paramInt, Object paramObject)
  {
    if (this.values.size() <= paramInt) {
      this.values.setSize(paramInt + 1);
    }
    if (paramObject != null) {
      assertTypeMatch(paramInt, paramObject);
    }
    this.values.setElementAt(paramObject, paramInt);
  }
  
  static void writeVarInt(OutputStream paramOutputStream, long paramLong)
    throws IOException
  {
    for (int i = 0;; i++)
    {
      int j;
      if (i < 10)
      {
        j = (int)(0x7F & paramLong);
        paramLong >>>= 7;
        if (paramLong == 0L) {
          paramOutputStream.write(j);
        }
      }
      else
      {
        return;
      }
      paramOutputStream.write(j | 0x80);
    }
  }
  
  private static long zigZagDecode(long paramLong)
  {
    return paramLong >>> 1 ^ -(1L & paramLong);
  }
  
  private static long zigZagEncode(long paramLong)
  {
    return paramLong << 1 ^ -(paramLong >>> 63);
  }
  
  public void addBool(int paramInt, boolean paramBoolean)
  {
    insertBool(paramInt, getCount(paramInt), paramBoolean);
  }
  
  public void addBytes(int paramInt, byte[] paramArrayOfByte)
  {
    insertBytes(paramInt, getCount(paramInt), paramArrayOfByte);
  }
  
  public void addDouble(int paramInt, double paramDouble)
  {
    insertDouble(paramInt, getCount(paramInt), paramDouble);
  }
  
  public void addFloat(int paramInt, float paramFloat)
  {
    insertFloat(paramInt, getCount(paramInt), paramFloat);
  }
  
  public void addInt(int paramInt1, int paramInt2)
  {
    insertInt(paramInt1, getCount(paramInt1), paramInt2);
  }
  
  public void addLong(int paramInt, long paramLong)
  {
    insertLong(paramInt, getCount(paramInt), paramLong);
  }
  
  public void addProtoBuf(int paramInt, ProtoBuf paramProtoBuf)
  {
    insertProtoBuf(paramInt, getCount(paramInt), paramProtoBuf);
  }
  
  public void addString(int paramInt, String paramString)
  {
    insertString(paramInt, getCount(paramInt), paramString);
  }
  
  public void clear()
  {
    this.values.setSize(0);
    this.wireTypes.setLength(0);
  }
  
  public ProtoBuf createGroup(int paramInt)
  {
    return new ProtoBuf((ProtoBufType)getType().getData(paramInt));
  }
  
  public boolean getBool(int paramInt)
  {
    return ((Boolean)getObject(paramInt, 24)).booleanValue();
  }
  
  public boolean getBool(int paramInt1, int paramInt2)
  {
    return ((Boolean)getObject(paramInt1, paramInt2, 24)).booleanValue();
  }
  
  public byte[] getBytes(int paramInt)
  {
    return (byte[])getObject(paramInt, 25);
  }
  
  public byte[] getBytes(int paramInt1, int paramInt2)
  {
    return (byte[])getObject(paramInt1, paramInt2, 25);
  }
  
  public int getCount(int var1) {
      if(var1 < this.values.size()) {
         Object var2 = this.values.elementAt(var1);
         if(var2 != null) {
            if(var2 instanceof Vector) {
               return ((Vector)var2).size();
            }
            return 1;
         }
      }
      return 0;
   }
  
  public int getDataSize()
  {
    int i = 0;
    for (int j = 0; j <= maxTag(); j++) {
      for (int k = 0; k < getCount(j); k++) {
        i += getDataSize(j, k);
      }
    }
    return i;
  }
  
  public double getDouble(int paramInt)
  {
    return Double.longBitsToDouble(getLong(paramInt));
  }
  
  public double getDouble(int paramInt1, int paramInt2)
  {
    return Double.longBitsToDouble(getLong(paramInt1, paramInt2));
  }
  
  public float getFloat(int paramInt)
  {
    return Float.intBitsToFloat(getInt(paramInt));
  }
  
  public float getFloat(int paramInt1, int paramInt2)
  {
    return Float.intBitsToFloat(getInt(paramInt1, paramInt2));
  }
  
  public int getInt(int paramInt)
  {
    return (int)((Long)getObject(paramInt, 21)).longValue();
  }
  
  public int getInt(int paramInt1, int paramInt2)
  {
    return (int)((Long)getObject(paramInt1, paramInt2, 21)).longValue();
  }
  
  public long getLong(int paramInt)
  {
    return ((Long)getObject(paramInt, 19)).longValue();
  }
  
  public long getLong(int paramInt1, int paramInt2)
  {
    return ((Long)getObject(paramInt1, paramInt2, 19)).longValue();
  }
  
  public ProtoBuf getProtoBuf(int paramInt)
  {
    return (ProtoBuf)getObject(paramInt, 26);
  }
  
  public ProtoBuf getProtoBuf(int paramInt1, int paramInt2)
  {
    return (ProtoBuf)getObject(paramInt1, paramInt2, 26);
  }
  
  public String getString(int paramInt)
  {
    return (String)getObject(paramInt, 28);
  }
  
  public String getString(int paramInt1, int paramInt2)
  {
    return (String)getObject(paramInt1, paramInt2, 28);
  }
  
  public int getType(int paramInt)
  {
    int i = 16;
    if (this.msgType != null) {
      i = this.msgType.getType(paramInt);
    }
    if ((i == 16) && (paramInt < this.wireTypes.length())) {
      i = this.wireTypes.charAt(paramInt);
    }
    if ((i == 16) && (getCount(paramInt) > 0))
    {
      Object localObject = getObject(paramInt, 0, 16);
      if (((localObject instanceof Long)) || ((localObject instanceof Boolean))) {
        i = 0;
      }
    }
    else
    {
      return i;
    }
    return 2;
  }
  
  public ProtoBufType getType()
  {
    return this.msgType;
  }
  
  public boolean has(int paramInt)
  {
    return (getCount(paramInt) > 0) || (getDefault(paramInt) != null);
  }
  
  public void insertBool(int paramInt1, int paramInt2, boolean paramBoolean)
  {
    if (paramBoolean) {}
    for (Boolean localBoolean = TRUE;; localBoolean = FALSE)
    {
      insertObject(paramInt1, paramInt2, localBoolean);
      return;
    }
  }
  
  public void insertBytes(int paramInt1, int paramInt2, byte[] paramArrayOfByte)
  {
    insertObject(paramInt1, paramInt2, paramArrayOfByte);
  }
  
  public void insertDouble(int paramInt1, int paramInt2, double paramDouble)
  {
    insertLong(paramInt1, paramInt2, Double.doubleToLongBits(paramDouble));
  }
  
  public void insertFloat(int paramInt1, int paramInt2, float paramFloat)
  {
    insertInt(paramInt1, paramInt2, Float.floatToIntBits(paramFloat));
  }
  
  public void insertInt(int paramInt1, int paramInt2, int paramInt3)
  {
    insertLong(paramInt1, paramInt2, paramInt3);
  }
  
  public void insertLong(int paramInt1, int paramInt2, long paramLong)
  {
    if ((paramLong >= 0L) && (paramLong < SMALL_NUMBERS.length)) {}
    for (Long localLong = SMALL_NUMBERS[((int)paramLong)];; localLong = new Long(paramLong))
    {
      insertObject(paramInt1, paramInt2, localLong);
      return;
    }
  }
  
  public void insertProtoBuf(int paramInt1, int paramInt2, ProtoBuf paramProtoBuf)
  {
    insertObject(paramInt1, paramInt2, paramProtoBuf);
  }
  
  public void insertString(int paramInt1, int paramInt2, String paramString)
  {
    insertObject(paramInt1, paramInt2, paramString);
  }
  
  public int maxTag()
  {
    return -1 + this.values.size();
  }
  
  public ProtoBuf newProtoBufForTag(int paramInt)
  {
    return new ProtoBuf((ProtoBufType)this.msgType.getData(paramInt));
  }
  public void outputTo(OutputStream var1) throws IOException {
      for(int var2 = 0; var2 <= this.maxTag(); ++var2) {
         int var3 = this.getCount(var2);
         int var4 = this.getWireType(var2);

         label51:
         for(int var5 = 0; var5 < var3; ++var5) {
            writeVarInt(var1, (long)(var4 | var2 << 3));
            switch(var4) {
            case 0:
               long var10 = ((Long)this.getObject(var2, var5, 19)).longValue();
               if(this.isZigZagEncodedType(var2)) {
                  var10 = zigZagEncode(var10);
               }

               writeVarInt(var1, var10);
               break;
            case 1:
            case 5:
               long var12 = ((Long)this.getObject(var2, var5, 19)).longValue();
               byte var14;
               if(var4 == 5) {
                  var14 = 4;
               } else {
                  var14 = 8;
               }

               int var15 = 0;

               while(true) {
                  if(var15 >= var14) {
                     continue label51;
                  }

                  var1.write((int)(255L & var12));
                  var12 >>= 8;
                  ++var15;
               }
            case 2:
               byte var6;
               if(this.getType(var2) == 27) {
                  var6 = 16;
               } else {
                  var6 = 25;
               }

               Object var7 = this.getObject(var2, var5, var6);
               if(var7 instanceof byte[]) {
                  byte[] var9 = (byte[])((byte[])var7);
                  writeVarInt(var1, (long)var9.length);
                  var1.write(var9);
               } else {
                  ProtoBuf var8 = (ProtoBuf)var7;
                  writeVarInt(var1, (long)var8.getDataSize());
                  var8.outputTo(var1);
               }
               break;
            case 3:
               ((ProtoBuf)this.getObject(var2, var5, 26)).outputTo(var1);
               writeVarInt(var1, (long)(4 | var2 << 3));
               break;
            case 4:
            default:
               throw new IllegalArgumentException();
            }
         }
      }

   }

  public int parse(InputStream var1, int var2) throws IOException {
      this.clear();

      while(true) {
         if(var2 > 0) {
            long var3 = readVarInt(var1, true);
            if(var3 != -1L) {
               var2 -= getVarIntSize(var3);
               int var5 = 7 & (int)var3;
               if(var5 != 4) {
                  int var6 = (int)(var3 >>> 3);

                  while(this.wireTypes.length() <= var6) {
                     this.wireTypes.append('\u0010');
                  }

                  Object var9;
                  this.wireTypes.setCharAt(var6, (char)var5);
                  ProtoBuf var10000;
                  label78:
                  switch(var5) {
                  case 0:
                     long var22 = readVarInt(var1, false);
                     var2 -= getVarIntSize(var22);
                     if(this.isZigZagEncodedType(var6)) {
                        var22 = zigZagDecode(var22);
                     }

                     if(var22 >= 0L && var22 < (long)SMALL_NUMBERS.length) {
                        var9 = SMALL_NUMBERS[(int)var22];
                     } else {
                        var9 = new Long(var22);
                     }
                     break;
                  case 1:
                  case 5:
                     long var16 = 0L;
                     int var18 = 0;
                     byte var19;
                     if(var5 == 5) {
                        var19 = 4;
                     } else {
                        var19 = 8;
                     }

                     var2 -= var19;
                     int var20 = var19;

                     while(true) {
                        int var21 = var20 - 1;
                        if(var20 <= 0) {
                           if(var16 >= 0L && var16 < (long)SMALL_NUMBERS.length) {
                              var9 = SMALL_NUMBERS[(int)var16];
                           } else {
                              var9 = new Long(var16);
                           }
                           break label78;
                        }

                        var16 |= (long)var1.read() << var18;
                        var18 += 8;
                        var20 = var21;
                     }
                  case 2:
                     int var10 = (int)readVarInt(var1, false);
                     var2 = var2 - getVarIntSize((long)var10) - var10;
                     if(this.getType(var6) == 27) {
                    	 ProtoBuf localProtoBuf2 = new ProtoBuf((ProtoBufType)this.msgType.getData(var6));
                         localProtoBuf2.parse(var1, var10);
                         var9 = localProtoBuf2;
                     } else {
                        byte[] var13 = new byte[var10];

                        int var15;
                        for(int var14 = 0; var14 < var10; var14 += var15) {
                           var15 = var1.read(var13, var14, var10 - var14);
                           if(var15 <= 0) {
                              throw new IOException("Unexp.EOF");
                           }
                        }

                        var9 = var13;
                     }
                     break;
                  case 3:
                     ProtoBufType var7;
                     if(this.msgType == null) {
                        var7 = null;
                     } else {
                        var7 = (ProtoBufType)this.msgType.getData(var6);
                     }

                     ProtoBuf localProtoBuf1 = new ProtoBuf(var7);
                     var2 = localProtoBuf1.parse(var1, var2);
                     var9 = localProtoBuf1;
                     break;
                  case 4:
                  default:
                     throw new RuntimeException("Unsupp.Type" + var5);
                  }

                  this.insertObject(var6, this.getCount(var6), var9);
                  continue;
               }
            }
         }

         if(var2 < 0) {
            throw new IOException();
         }

         return var2;
      }
   }

  
  public ProtoBuf parse(InputStream paramInputStream)
    throws IOException
  {
    parse(paramInputStream, 2147483647);
    return this;
  }
  
  public ProtoBuf parse(byte[] paramArrayOfByte)
    throws IOException
  {
    parse(new ByteArrayInputStream(paramArrayOfByte), paramArrayOfByte.length);
    return this;
  }
  
  public void remove(int paramInt1, int paramInt2)
  {
    int i = getCount(paramInt1);
    if (paramInt2 >= i) {
      throw new ArrayIndexOutOfBoundsException();
    }
    if (i == 1)
    {
      this.values.setElementAt(null, paramInt1);
      return;
    }
    ((Vector)this.values.elementAt(paramInt1)).removeElementAt(paramInt2);
  }
  
  public void setBool(int paramInt, boolean paramBoolean)
  {
    if (paramBoolean) {}
    for (Boolean localBoolean = TRUE;; localBoolean = FALSE)
    {
      setObject(paramInt, localBoolean);
      return;
    }
  }
  
  public void setBytes(int paramInt, byte[] paramArrayOfByte)
  {
    setObject(paramInt, paramArrayOfByte);
  }
  
  public void setDouble(int paramInt, double paramDouble)
  {
    setLong(paramInt, Double.doubleToLongBits(paramDouble));
  }
  
  public void setFloat(int paramInt, float paramFloat)
  {
    setInt(paramInt, Float.floatToIntBits(paramFloat));
  }
  
  public void setInt(int paramInt1, int paramInt2)
  {
    setLong(paramInt1, paramInt2);
  }
  
  public void setLong(int paramInt, long paramLong)
  {
    if ((paramLong >= 0L) && (paramLong < SMALL_NUMBERS.length)) {}
    for (Long localLong = SMALL_NUMBERS[((int)paramLong)];; localLong = new Long(paramLong))
    {
      setObject(paramInt, localLong);
      return;
    }
  }
  
  public ProtoBuf setNewProtoBuf(int paramInt)
  {
    ProtoBuf localProtoBuf = newProtoBufForTag(paramInt);
    addProtoBuf(paramInt, localProtoBuf);
    return localProtoBuf;
  }
  
  public void setProtoBuf(int paramInt, ProtoBuf paramProtoBuf)
  {
    setObject(paramInt, paramProtoBuf);
  }
  
  public void setString(int paramInt, String paramString)
  {
    setObject(paramInt, paramString);
  }
  
  void setType(ProtoBufType paramProtoBufType)
  {
    if ((this.values.size() != 0) || ((this.msgType != null) && (paramProtoBufType != null) && (paramProtoBufType != this.msgType))) {
      throw new IllegalArgumentException();
    }
    this.msgType = paramProtoBufType;
  }
  
  public byte[] toByteArray()
    throws IOException
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    outputTo(localByteArrayOutputStream);
    return localByteArrayOutputStream.toByteArray();
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.gmail.ProtoBuf
 * JD-Core Version:    0.7.0.1
 */